<template>
  <el-dialog
    title="请选择日期"
    :visible.sync="dialogVisible"
    width="250px">
    <div>
      <el-date-picker
        style="width: 70%;"
        v-model="dateTime"
        value-format="yyyy-MM-dd"
        type="date"
      placeholder="请选选择日期">
      </el-date-picker>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm">确认选择</el-button>
    </div>
  </el-dialog>

</template>

<script>
export default {
  name: 'ChooseDateDialog',
  data: function () {
    return {
      callback:null,
      dialogVisible:false,
      dateTime:'',
    }
  },
  mounted () {
    let $this = this
    $this.bus.$on('BackKeyCallBus',function (){
      $this.dialogVisible=false
      $this.$forceUpdate()
    })
    $this.bus.$on('ChooseDateDialogCallBus', function (dateTime,callback) {
      $this.dialogVisible = true
      $this.callback=callback
      if (dateTime){
        $this.dateTime=dateTime
      }
      $this.$forceUpdate()
    })

  },
  methods: {
    confirm:function () {
      if (typeof this.callback==='function'){
        this.callback(this.dateTime)
        this.dialogVisible = false
      }
    }
  }
}
</script>

<style scoped>

</style>
